using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Samples.BizTalk.Adapter.Tcp
{
    /// <summary>
    ///     This interface represents a worker thread used by the dispatcher.
    /// </summary>
    /// <author>
    ///     Paul Brown
    /// </author>
    public interface IWorkerThread : IDisposable
    {
        #region Events

        /// <summary>
        ///     This event is fired just before the worker thread terminates.
        /// </summary>
        event EventHandler ThreadTerminated;

        #endregion

        #region Properties

        /// <summary>
        ///     This property returns whether the object has been disposed of.
        /// </summary>
        bool IsDisposed
        {
            get;
        }

        /// <summary>
        ///     This property returns whether the worker thread is currently stopping.
        /// </summary>
        bool IsStopping
        {
            get;
        }

        /// <summary>
        ///     This property returns whether the worker thread is currently stopped.
        /// </summary>
        bool IsStopped
        {
            get;
        }

        /// <summary>
        ///     This property returns whether the worker thread is idle or not.
        /// </summary>
        bool IsIdle
        {
            get;
        }

        /// <summary>
        ///     This property returns the time that a thread has been idle.
        /// </summary>
        TimeSpan IdleTime
        {
            get;
        }

        /// <summary>
        ///     This property returns whether the worker thread was terminated due to being idle if it has stopped.
        /// </summary>
        bool HasIdleTerminated
        {
            get;
        }

        /// <summary>
        ///     This property returns the current workload of a thread.
        /// </summary>
        int CurrentWorkLoad
        {
            get;
        }

        /// <summary>
        ///     This property returns the type of work item that this worker thread supports.
        /// </summary>
        Type WorkItemType
        {
            get;
        }

        /// <summary>
        ///     This property gets the name of the worker thread.
        /// </summary>
        string Name
        {
            get;
        }

        /// <summary>
        ///     This property returns the adapter that the worker thread is associated with.
        /// </summary>
        IAdapter Adapter
        {
            get;
        }

        #endregion

        #region Methods

        /// <summary>
        ///     This method starts the worker thread.
        /// </summary>
        void Start();

        /// <summary>
        ///     This method stops the worker thread.
        /// </summary>
        void Stop();

        /// <summary>
        ///     This method stops the worker thread with a flag that indicates whether the stop was invoked
        ///     due to the thread idling or not.
        /// </summary>
        void Stop(bool idleTerminated);

        /// <summary>
        ///     This method causes the worker thread to do the work associated with the work item.
        /// </summary>
        void DoWork(IWorkItem workItem);

        #endregion
    }
}
